package com.centaline.androidsalesblog.adapter.viewholder;

import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.DrawableRequestBuilder;
import com.centaline.androidsalesblog.R;
import com.centaline.androidsalesblog.model.databaseobject.NewEstDo;
import com.centaline.androidsalesblog.utils.PriceUtil;
import com.centanet.framework.glide.GlideLoad;

import java.util.Locale;

/**
 * 足迹---新房
 * <p/>
 * Created by fusl1 on 2015/12/24.
 */
public class FpNewVH extends RecyclerView.ViewHolder {

    public ImageView img_indicator, img_logo;
    public AppCompatTextView atv_title, atv_tag_fir, atv_tag_sec, atv_price, atv_est_type;

    public FpNewVH(View itemView) {
        super(itemView);
        img_indicator = (ImageView) itemView.findViewById(R.id.img_indicator);
        img_logo = (ImageView) itemView.findViewById(R.id.img_logo);
        atv_title = (AppCompatTextView) itemView.findViewById(R.id.atv_title);
        atv_tag_fir = (AppCompatTextView) itemView.findViewById(R.id.atv_tag_fir);
        atv_tag_sec = (AppCompatTextView) itemView.findViewById(R.id.atv_tag_sec);
        atv_price = (AppCompatTextView) itemView.findViewById(R.id.atv_price);
        atv_est_type = (AppCompatTextView) itemView.findViewById(R.id.atv_est_type);
    }

    public void load(DrawableRequestBuilder<String> requestBuilder, NewEstDo newEstDo, String newPropImg ,
                     int mode,boolean select) {
        img_indicator.setImageResource(mode == 0 ? R.drawable.ic_history_point_2 :
                select ? R.drawable.ic_order_btn_sel : R.drawable.ic_order_btn_nor);
        String imgAddr = newEstDo.getIconUrl();
        imgAddr = imgAddr == null || !imgAddr.contains(".") ? "" : imgAddr.replace(".", "_200x200_f.");
        GlideLoad.load(new GlideLoad.Builder(requestBuilder, String.format(Locale.CHINA, "%s%s", newPropImg, imgAddr))
                .placeHolder(R.drawable.ic_centa_square_logo)
                .error(R.drawable.ic_centa_square_logo)
                .openWifiSwitch()
                .into(img_logo));
        atv_title.setText(newEstDo.getAdName());
        atv_tag_fir.setText(String.format(Locale.CHINA, "%s  %s", newEstDo.getRegionName(), newEstDo.getGscopName()));
        atv_tag_sec.setText(newEstDo.getAddress());
        atv_price.setText(PriceUtil.newEstAvgPrice(newEstDo.getAveragePrice()));
        atv_est_type.setText(newEstDo.getEstType());
    }
}
